package andev.schoolhelper.welcome;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;

import andev.aandroidlib.activity.AActivity;
import andev.schoolhelper.R;
import andev.schoolhelper.login.LoginActivity;
import andev.schoolhelper.main.MainActivity;

public class WelcomeActivity extends AActivity {
    private static boolean bAlreadyWelcome = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (bAlreadyWelcome == true) {
            judgeGoActivity();
            return;
        }
        setContentView(R.layout.activity_welcome);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                bAlreadyWelcome = true;
                judgeGoActivity();
            }
        }, 1000);
    }

    private boolean IsLogin() {
        SharedPreferences loginPreferences = getApplicationContext().getSharedPreferences("Login", Context.MODE_PRIVATE);
        return loginPreferences.getBoolean("bAlreadyLogin", false);
    }

    private void judgeGoActivity() {
        if (IsLogin()) {
            goActivity(MainActivity.class);
        } else {
            goActivity(LoginActivity.class);
        }
    }

    @Override
    public void onBackPressed() {
    }
}
